namespace Mvc.Controllers {
    using System.Web.Mvc;
    using Models;
    using Services;

    [HandleError]
    public class HomeController : Controller {
        public IMessageService MessageService { get; set; }

        public HomeController(IMessageService messageService) {
            MessageService = messageService;
        }

        public ActionResult Index() {
            var welcomeMessge = MessageService.GetDefaultMessage();
            return View(new MessageViewModel { Text = welcomeMessge });
        }

        public ActionResult About() {
            var aboutMessage = MessageService.GetAboutMessage();
            return View(new MessageViewModel { Text = aboutMessage });
        }

        //NOTE: No need to specify an About action since empty actions are inferred.

        protected override void OnActionExecuted(ActionExecutedContext filterContext) {
            base.OnActionExecuted(filterContext);

            ViewData["InstanceMessage"] = MessageService.GetInternalMessage();
            ViewData["SimpleMessages"] = MessageService.GetMessages();
        }
    }
}
